// Types
export interface StringKey_NumberData_Object {
    [key: string]: number;
}

export interface ResultItem {
    letter: string;
    status: "exclude" | "include" | "correct";
}

// Functions
export function deepClone<T>(value: T, map = new WeakMap<any, any>()): T {
    if (value === null || typeof value !== "object") {
        return value;
    }

    if (map.has(value)) {
        return map.get(value);
    }

    if (value instanceof Date) {
        return new Date(value.getTime()) as T;
    }

    if (value instanceof RegExp) {
        return new RegExp(value) as T;
    }

    if (Array.isArray(value)) {
        const arrCopy: any[] = [];
        map.set(value, arrCopy);
        for (let i = 0; i < value.length; i++) {
            arrCopy[i] = deepClone(value[i], map);
        }
        return arrCopy as T;
    }

    const objCopy: { [key: string]: any } = {};
    map.set(value, objCopy);
    for (const key in value) {
        if (value.hasOwnProperty(key)) {
            objCopy[key] = deepClone(value[key], map);
        }
    }

    return objCopy as T;
}
